
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class vwAllocatedVenuesComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public vwAllocatedVenuesComponent()
        {

        }

	
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<vwAllocatedVenues> SelectAll(string sortExpression)
        {
            List<vwAllocatedVenues> listvwAllocatedVenues = new List<vwAllocatedVenues>();
            PlacementManager.DAL.vwAllocatedVenues_DAL o = new PlacementManager.DAL.vwAllocatedVenues_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listvwAllocatedVenues.Add(new vwAllocatedVenues((int)row["VenuePlacementTypeId"], (int)row["VenueId"], (int)row["PlacementTypeId"], (bool)row["IsRestricted"], (int)row["MaxNumStudents"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"], (string)row["VenueName"], (bool)row["VenueSuppliedEducator"], (string)row["TelephoneNumber"], (string)row["Fax"], (string)row["GenericEmail"], (bool)row["VenueIsActive"], (string)row["Address1"], (string)row["Address2"], (string)row["City"], (string)row["PostCode"], (int)row["StateId"], (int)row["CountryId"], (bool)row["IsPostal"], (bool)row["AddressIsActive"], (bool)row["LinkVenueAddressIsActive"], (bool)row["IsPrimary"], (double)row["Latitude"], (double)row["Longitude"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listvwAllocatedVenues.Sort(new vwAllocatedVenuesComparer(sortExpression));
            return listvwAllocatedVenues;
        }
	}
	
	public class vwAllocatedVenuesComparer : IComparer<vwAllocatedVenues>
    {
        private string _sortColumn;
        private bool _reverse;

        public vwAllocatedVenuesComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(vwAllocatedVenues a, vwAllocatedVenues b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "VenuePlacementTypeId":
					retVal = String.Compare(a.VenuePlacementTypeId.ToString(), b.VenuePlacementTypeId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueId":
					retVal = String.Compare(a.VenueId.ToString(), b.VenueId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "PlacementTypeId":
					retVal = String.Compare(a.PlacementTypeId.ToString(), b.PlacementTypeId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsRestricted":
					retVal = String.Compare(a.IsRestricted.ToString(), b.IsRestricted.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "MaxNumStudents":
					retVal = String.Compare(a.MaxNumStudents.ToString(), b.MaxNumStudents.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueName":
					retVal = String.Compare(a.VenueName.ToString(), b.VenueName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueSuppliedEducator":
					retVal = String.Compare(a.VenueSuppliedEducator.ToString(), b.VenueSuppliedEducator.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "TelephoneNumber":
					retVal = String.Compare(a.TelephoneNumber.ToString(), b.TelephoneNumber.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Fax":
					retVal = String.Compare(a.Fax.ToString(), b.Fax.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "GenericEmail":
					retVal = String.Compare(a.GenericEmail.ToString(), b.GenericEmail.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueIsActive":
					retVal = String.Compare(a.VenueIsActive.ToString(), b.VenueIsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Address1":
					retVal = String.Compare(a.Address1.ToString(), b.Address1.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Address2":
					retVal = String.Compare(a.Address2.ToString(), b.Address2.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "City":
					retVal = String.Compare(a.City.ToString(), b.City.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "PostCode":
					retVal = String.Compare(a.PostCode.ToString(), b.PostCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "StateId":
					retVal = String.Compare(a.StateId.ToString(), b.StateId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CountryId":
					retVal = String.Compare(a.CountryId.ToString(), b.CountryId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsPostal":
					retVal = String.Compare(a.IsPostal.ToString(), b.IsPostal.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AddressIsActive":
					retVal = String.Compare(a.AddressIsActive.ToString(), b.AddressIsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "LinkVenueAddressIsActive":
					retVal = String.Compare(a.LinkVenueAddressIsActive.ToString(), b.LinkVenueAddressIsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsPrimary":
					retVal = String.Compare(a.IsPrimary.ToString(), b.IsPrimary.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Latitude":
					retVal = String.Compare(a.Latitude.ToString(), b.Latitude.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Longitude":
					retVal = String.Compare(a.Longitude.ToString(), b.Longitude.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
	
